<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/homepages/css/main.css" type="text/css"></link>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/icon.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.1.2.2.js"></script>
     <script type="text/javascript" src="${pageContext.request.contextPath}/homepages/js/forms.js"></script>
     <script type="text/javascript">
     	var a = document.documentElement.clientHeight - 72;
		var b = document.documentElement.clientWidth - 25;
			
		var basePath = "/";
		$(function(){
			basePath = '${pageContext.request.contextPath}';
			$('#DATALIST').datagrid({
				iconCls:'icon-save',
				nowrap: false,
				width:b,
				height:a,
				striped: true,				 
				collapsible:true,
				autoRowHeight: false,		
				//sortName: 'code',
				//sortOrder: 'desc',
				remoteSort: false,
				//idField:'code',
				fitColumns:true,
				singleSelect:true,
				columns:[[]],
				pagination:true,
				rownumbers:true
			});
			var configId= $('#configId').val();  
			var funcsId = $('#funcsId').val();
			$.ajax({
			   url: "${pageContext.request.contextPath}/pageConfig/createPages",
			   type:"post",
			   data: {'configId':configId,'funcsId':funcsId},
			   success: function(data){
			   		var columns = data.queryColumns;
			   		var buttons = data.buttons;			//按钮
			   		var datagridPro =data.columns;
					var clnObj = $('#COLUMNS');
					var butObj = $('#BUTTONS');
					var clnHTML = "";
					var clineCount = 3;
					var rowCount = 0;
					for(var i = 0; i < columns.length; i++){
						if(rowCount%clineCount == 0)clnHTML += "<tr>";
						clnHTML += "<td>"+columns[i].colnName+"</td>";
						clnHTML += "<td>"+formatInputObj(columns[i])+"</td>";
						rowCount++;
						if(rowCount%clineCount == 0)clnHTML += "</tr>";
					}
					clnObj.html(clnHTML);
					var blineCount = 3;
					var butHTML = "";
					rowCount = 0;
					for(var i = 0; i < buttons.length; i++){
						butHTML += "<input type='button' value='"+buttons[i].butnName+"' onclick="+buttons[i].scriptFunc+" />";
					}
					butObj.html(butHTML);
					
					var dataGrid = $('#DATALIST');
					var options = {  
							rownumbers: true  
						};
					var columns = new Array();
					for(var i = 0; i < datagridPro.length; i++){
						var column = {};
						column.title = datagridPro[i].colnName
						column.field = datagridPro[i].name;
						column.width = 100;
						column.editor = datagridPro[i].format;
						columns[i] = column;
					}
					var cc = new Array();
					cc[0] = columns;
					options.columns = (cc);
					dataGrid.datagrid(options);//根据配置选项，生成datagrid  
					dataGrid.datagrid("loadData", data);
				}
			});
		});
		
		function resizeGrid(){
			var a = document.documentElement.clientHeight - 72;
			var b = document.documentElement.clientWidth - 25;
			$('#DATALIST').datagrid('resize', {
				width:b,
				height:a
 	  		 });
		}
		
		 function formatInputObj(clnObj) {
			var inpHTML = "";
			var inpType = clnObj.inputType;
			var ediType = clnObj.ediType;
			var properName = "";
			if (clnObj.javaClass != null || clnObj.javaProperty != null
					|| clnObj.javaClass != "" || clnObj.javaProperty != "") {
				if (clnObj.javaClass != null && clnObj.javaProperty != null
						&& clnObj.javaClass != "" && clnObj.javaProperty != "") {
					properName = "name='" + clnObj.javaClass + "."
							+ clnObj.javaProperty + "'"
				}
				if ((clnObj.javaClass == null || clnObj.javaClass == "")
						&& (clnObj.javaProperty != null || clnObj.javaProperty != "")) {
					properName = "name='" + clnObj.javaProperty + "'"
				}
			}
			var openLoadSameStr = "";
			if (clnObj.openLoadSameStr == 'T' && clnObj.openLoadType != null
					&& clnObj.openLoadType != ""
					&& (inpType == 'input' || inpType == null || inpType == '')) {
				//查找相似的数据
				//openLoadSameStr = "  onkeydown= if(event.keyCode==13)loadSameStr(this,'"+clnObj.openLoadType+"','"+basePath+"');";
			}
			var width = clnObj.width;
			if (width == 0) {
				width = "width:100%;"
			} else {
				width = "width:" + width + "px;"
			}
			var height = clnObj.height;
			if (height == 0) {
				height = ""
			} else {
				height = "height:" + height + "px;"
			}
			var javaClass = clnObj.javaClass;
			var readOnly = clnObj.readOnly;
			var properties = properName + " " + openLoadSameStr;
			//对象类型 char integer number date time datetime input
			// datalist select textarea
			//radio checkbox [treelist] email
			//[link] password file [multivalue]
			switch (inpType) {
			case　"password":
				inpHTML ="<input " + properties + " type=\"password\" style='" + width+ height + "'/>";
				break;
			case　"file":
				inpHTML ="<input " + properties + " type=\"file\" style='" + width+ height + "'/>";
				break;
			case "radio":
				inpHTML ="<input " + properties + " type=\"radio\" style='" + width+ height + "'/>";
				break;
			case "checkbox":
				inpHTML ="<input " + properties + " type=\"checkbox\" style='" + width+ height + "'/>";
				break;
			case "email":   
				inpHTML ="<input " + properties + " id=\"email\" style='" + width+ height + "' onblur=\"checkNum(this)\"/>";
				break;
			case "select":
				inpHTML = "<select " + properties + " style='" + width + height 
						+ "' onClick=\"loadData()\"></select>";
				break;
			case "textarea":
				inpHTML = "<textarea " + properties +  "style='"+ width+ height+ "'></textarea>";
				break;
			case "datetime":
				inpHTML = "<input "+ properties+ " style='"+ width+ height+ "' onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\"/>";
				break;
			case "integer":
				inpHTML = "<input " + properties + " id=\"intnum\" style='" + width
						+ height + "' onblur=\"checkNum(this)\"/>";
				break;
			case "number":
				inpHTML = "<input " + properties + " id=\"number\" style='" + width
						+ height + "' onblur=\"checkNum(this)\"/>";
				break;
			case "date":
				inpHTML = "<input " + properties + " style='" + width + height
						+ "' onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\"/>";
				break;
			case "time":
				inpHTML = "<input " + properties + " style='" + width + height
						+ "' onClick=\"WdatePicker({dateFmt:'HH:mm:ss'})\"/>";
				break;
			case "datalist":
				inpHTML = "<select " + properties + " style='" + width + height
						+ "' onClick=\"showDialog()\"></select>";
				break;
			default:
				inpHTML = "<input " + properties + " style='" + width + height
						+ "'/>";
			}
			return inpHTML;
		}
     </script>
     
     
     
  </head>
  
 <body  onresize="resizeGrid();">
	<form action="" method="post" id="queryForm">
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td>
					<!-- 部分查询框 -->
					<table id="COLUMNS">
					</table>
				</td>
				<td style="vertical-align: top;">
					<!-- 部分按钮 -->
					<div id="BUTTONS" style="width:195px;padding-left: 20px;"></div>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<!-- 数据列表 -->	
					<table  id="DATALIST"></table>
				</td>
			</tr>
		</table>
	</form>
	<input type="hidden" id="configId" value="${configId}"/>
	<input type="hidden" id="funcsId" value="${funcsId}"/>
</body>
</html>
